package com.lidastudio.dbdatamock.util;

import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;

public class DatabaseUtil {
	
	public static HikariDataSource getDataSource(String host, Integer port, String dbName, String username, String password) {
		/*
		ds = DataSourceBuilder.create()
					.url("jdbc:mysql://" + host + "/" + dbName + "?useSSL=false&useUnicode=true&characterEncoding=UTF-8")
					.username(username)
					.password(password)
					.driverClassName("com.mysql.cj.jdbc.Driver")
					.build();
		*/
		 HikariConfig hikariConfig = new HikariConfig();
		 hikariConfig.setJdbcUrl("jdbc:mysql://" + host + "/" + dbName + "?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai");
		 hikariConfig.setUsername(username);
		 hikariConfig.setPassword(password);
		 hikariConfig.setDriverClassName("com.mysql.cj.jdbc.Driver");
		 hikariConfig.setMaximumPoolSize(40);
		 hikariConfig.setMinimumIdle(10);
		 hikariConfig.setValidationTimeout(3000);
		 HikariDataSource hikariDataSource = new HikariDataSource(hikariConfig);
		  
		 return hikariDataSource;
	}

}
